package com.raptor.trustworthycore.util;
/**
 * 异常处理工具类
 * @author renhuan
 *
 */
public class ExceptionUtil {
	/**
	 * 创建异常堆栈信息
	 * @param message
	 * @param cause
	 * @return
	 */
	public static String buildMessage(String message, Throwable cause) {
		if (cause != null) {
			StringBuilder buf = new StringBuilder();
			if (message != null) {
				buf.append(message).append("; ");
			}
			buf.append("nested exception is ").append(cause);
			return buf.toString();
		}
		else {
			return message;
		}
	}

	/**
	 * 对异常信息长度截取
	 */
	public static String subExceptionMessage(String message, int length) {
		if (message != null){
			if (message.length() > length){
				message = message.substring(0, length -1);
			}
			return message;
		} else {
			return "";
		}
	}
}
